<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Product extends CI_Controller {
	public function detail($id){
		$this->load->model('Product_model');
		$this->load->model('Product_img_model');
		$data=array(
			'product'=>$this->Product_model->get_one($id),
			'imgs'=>$this->Product_img_model->get_product_img($id)
		);
		$this->load->view('Product_detail',$data);
	}
	public function lists($catalog_id){
		$this->load->model('Product_catalog_model');
		$this->load->model('Product_model');
		$this->load->model('Product_img_model');
		$catalog=$this->Product_catalog_model->get_one($catalog_id);
		if($catalog->parent_id==0){
			$child_catalogs=$this->Product_catalog_model->get_parent_lists($catalog->parent_id);
			redirect('Product/lists/'.$child_catalogs[0]->id);
		}
		//下面方法用在了product_model中
		// $child_catalogs=$this->Product_catalog_model->get_parent_lists($catalog_id);
		// $where=array($catalog_id);
		// foreach($child_catalogs as $c){
		// 	$where[]=$c->id;
		// }
		$brand_id=$this->input->get('brand');
		$data=array(
			'catalog'=>$catalog,
			'products_imgs'=>$this->Product_model->get_child_id_img($catalog_id,$brand_id),
			//'products_imgs'=>$this->Product_model->get_child_id_img($where,$brand_id),
			//'brands'=>$this->Product_model->get_brand_by_id($where,$brand_id),
			'parent_catalog'=>$this->Product_catalog_model->get_one($catalog->parent_id),
			'child_catalogs'=>$this->Product_catalog_model->get_parent_lists($catalog->parent_id),
			'brands'=>$this->Product_model->get_brand_by_id($catalog_id),
			
		);
		
		
		$this->load->view('Product_lists',$data);
	}
}
